﻿
Imports System.IO
Imports std
Imports storoomc

Public Class slice4
    Inherits slice3

    Public Shadows Class atom
        Inherits _atom_base
        Public guid As Int32 = 0

        Private Shared Function rnd2() As Int32
            Return rnd(0, Convert.ToInt32(maxUInt16) + 1, True)
        End Function

        Public Overrides Sub createGUID()
            guid = (rnd2() << (Global.sizeof(Of Int16)() * 8)) + rnd2()
        End Sub
    End Class

    Private Shared Shadows Function c(ByVal a As _atom_base) As atom
        Return convertor.cast(Of atom)(a)
    End Function

    Private Overloads Function datafile(ByVal atom As atom) As String
        Dim bts As bytes = Nothing
        bts = convertor.tobytes(atom.guid)
        Dim path As String = Nothing
        Dim i As Int64
        path = Convert.ToString(bts(0))
        For i = 1 To bts.size() - 2
            path = combinepath(path, Convert.ToString(bts(i)))
        Next
        Dim file As String = Nothing
        file = Convert.ToString(bts(bts.size() - 1))
        Dim fullpath As String = Nothing
        fullpath = combinepath(datarootpath(), path)
        createDirectory(fullpath)

        Return combinepath(fullpath, file)
    End Function

    Protected Overrides Function datafile(ByVal atom As _atom_base) As String
        Return datafile(c(atom))
    End Function

    Protected Overrides Function _atom_ctor() As _atom_base
        Return New atom()
    End Function

    Protected Overrides Function filter_slicetype_value() As String
        Return configNaming.filter.value.slicetype.slice4
    End Function

    Protected Overrides Function readguid(ByVal atom As _atom_base) As Boolean
        Return binaryReaderHelper.readInt32(reader(), c(atom).guid)
    End Function

    Protected Overrides Sub writeguid(ByVal a As _atom_base)
        writer().Write(c(a).guid)
    End Sub

    Protected Overrides Function maxSupportVersion() As String
        Return "3"
    End Function

    Protected Overrides Function minSupportVersion() As String
        Return "3"
    End Function

    Protected Overrides Function version() As String
        Return "3"
    End Function
End Class
